package com.example.ivideo_2211a.search

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.common.mvi.BaseActivity
import com.example.ivideo_2211a.R
import com.example.ivideo_2211a.databinding.ActivitySearchDetailtBinding
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

@Route(path = "/app/SearchDetailtActivity")
class SearchDetailtActivity : BaseActivity<ActivitySearchDetailtBinding, SearchViewModel, SearchIntent, SearchViewState>() {
    override val viewModel by viewModels<SearchViewModel>()
    @Autowired
    @JvmField
    var videoInfo: String = ""
    lateinit var videoDetailAdapter: SearchDetailVideoAdapter

    override fun getLayoutId()=R.layout.activity_search_detailt

    override fun setupViews() {
       ARouter.getInstance().inject(this)
        currentVideoAdapter()
        videoDetailAdapter.setOnItemClickListener(object :SearchDetailVideoAdapter.OnItemClickListener{
            override fun onItemClick(data: SearchDataEntity) {
                val toJson = Gson().toJson(data)
                ARouter.getInstance()
                    .build("/playvideo/PlayVideoActivity")  // 修正：添加模块前缀
                    .withString("videoDataJson", toJson)
                    .navigation()
            }

        })


    }

    private fun currentVideoAdapter() {
        val value = object : TypeToken<List<SearchDataEntity>>(){}.type
        val videoList = Gson().fromJson<List<SearchDataEntity>>(videoInfo, value)
        videoDetailAdapter = SearchDetailVideoAdapter(videoList)
        binding.recyclerView.adapter=   videoDetailAdapter


    }

    override fun renderViewState(state: SearchViewState) {

    }
}


